package com.scgk.sync.config;


import cn.hutool.core.lang.Console;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.net.Inet4Address;

/**
 * 启动服务控制台打印接口文档地址
 */
@Component
public class SwaggerPrintConfig implements ApplicationListener<WebServerInitializedEvent> {
    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        try{
            String hostAddress = Inet4Address.getLocalHost().getHostAddress();
            int port = event.getWebServer().getPort();
            String applicationName = event.getApplicationContext().getApplicationName();
            Console.log("启动成功... 接口文档地址：http://{}:{}{}/doc.html", hostAddress, port, applicationName);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
